//
//  PayViewController.m
//  FaceTo
//
//  Created by 程邦明 on 2017/8/8.
//  Copyright © 2017年 chengbangming. All rights reserved.
//

#import "PayViewController.h"
#import "allPriceTableViewCell.h"
#import "DiscountsTableViewCell.h"
#import "LastPayTableViewCell.h"
#import "OtherYouHuiTableViewCell.h"
#import "PayWayTableViewCell.h"



@interface PayViewController ()<UITableViewDelegate,UITableViewDataSource>
{
    NSArray * titleArray;
    NSArray * imageArray;
    
}
@property (nonatomic ,strong) UITableView * tableView;
@property (nonatomic ,strong) UIButton * payBtn;
@end

@implementation PayViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.view.backgroundColor = Color(235, 235, 235);
    titleArray = @[@"支付宝支付",@"微信支付"];
    imageArray = @[@"alipay",@"wechat"];
    [self initUI];
}
- (void)initUI{
    _tableView = [[UITableView alloc]initWithFrame:CGRectMake(0, 0, kSCREEN_WIDTH, kSCREEN_HEIGHT) style:UITableViewStyleGrouped];
    _tableView.backgroundColor = Color(235, 235, 235);
    _tableView.delegate = self;
    _tableView.dataSource = self;
    [self.view addSubview:_tableView];
    
    _payBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    _payBtn.frame = CGRectMake(10, kSCREEN_HEIGHT-60, kSCREEN_WIDTH-20, 40);
    [_payBtn setTitle:@"确认支付" forState:UIControlStateNormal];
    [_payBtn setTitleColor:Color(51, 51, 51) forState:UIControlStateNormal];
    [_payBtn setBackgroundColor:Color(255, 210, 48)];
    _payBtn.layer.masksToBounds = YES;
    _payBtn.layer.cornerRadius = 4;
    [_payBtn addTarget:self action:@selector(Pay) forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview:_payBtn];
    
}
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
    return 4;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    if(section == 0){
        return 1;
    }else if (section == 1){
        return 1;
    }else if (section == 2){
        return 2;
    }else{
        return 2;
    }
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    if(indexPath.section == 0){
        static NSString * identifier=@"cellIde";
        allPriceTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:identifier];
        if (cell == nil) {
            cell = [[allPriceTableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:identifier];
        }
        return cell;
    }else if (indexPath.section == 1){
        static NSString * identifier=@"cellIde1";
        DiscountsTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:identifier];
        if (cell == nil) {
            cell = [[DiscountsTableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:identifier];
        }
        return cell;
    }else if (indexPath.section == 2){
        if(indexPath.row == 0){
            static NSString * identifier=@"cellIde2";
            OtherYouHuiTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:identifier];
            if (cell == nil) {
                cell = [[OtherYouHuiTableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:identifier];
            }
            return cell;
        }else{
            static NSString * identifier=@"cellIde3";
            LastPayTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:identifier];
            if (cell == nil) {
                cell = [[LastPayTableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:identifier];
            }
            return cell;
        }
    }else{
        static NSString * identifier=@"cellIde4";
        PayWayTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:identifier];
        if (cell == nil) {
            cell = [[PayWayTableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:identifier];
        }
        cell.nameLabel.text = titleArray[indexPath.row];
        cell.headIamge.image = [UIImage imageNamed:imageArray[indexPath.row]];
        return cell;
    }
}
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    if(indexPath.section == 0){
        return 90;
    }else if (indexPath.section == 1){
        return 40;
    }else if (indexPath.section == 2){
        return 35;
    }else{
        return 50;
    }
}
- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section{
    if(section == 0){
        UIView *view=[[UIView alloc] initWithFrame:CGRectMake(0, 0, kSCREEN_WIDTH, 10)];
        return view;
        
    }else if (section == 1){
        UIView *view=[[UIView alloc] initWithFrame:CGRectMake(0, 0, kSCREEN_WIDTH, 25)];
        view.backgroundColor = Color(235, 235, 235);
        UILabel * nameLabel = [[UILabel alloc]initWithFrame:CGRectMake(10, 10, 200, 15)];
        nameLabel.text = @"优惠券";
        nameLabel.textAlignment = NSTextAlignmentLeft;
        nameLabel.font = [UIFont systemFontOfSize:14];
        nameLabel.textColor = BlackColor;
        [view addSubview:nameLabel];
        return view;
    }else if (section == 2){
        UIView *view=[[UIView alloc] initWithFrame:CGRectMake(0, 0, kSCREEN_WIDTH, 15)];
        return view;
    }else{
        UIView *view=[[UIView alloc] initWithFrame:CGRectMake(0, 0, kSCREEN_WIDTH, 25)];
        view.backgroundColor = Color(235, 235, 235);
        UILabel * nameLabel = [[UILabel alloc]initWithFrame:CGRectMake(10, 10, 200, 15)];
        nameLabel.text = @"支付方式";
        nameLabel.textAlignment = NSTextAlignmentLeft;
        nameLabel.font = [UIFont systemFontOfSize:14];
        nameLabel.textColor = BlackColor;
        [view addSubview:nameLabel];
        return view;
    }
}
//改每个Group的间距
- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section{
    if(section == 0){
        return 10;
    }else if (section == 1){
        return 40;
    }else if (section == 2){
        return 15;
    }else{
        return 40;
    }
    
}
- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section{
    return 0.1;
}
- (UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section{
    UIView *view=[[UIView alloc] initWithFrame:CGRectMake(0, 0, kSCREEN_WIDTH, 0.1)];
    return view;
}
- (void)Pay{
    
}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
